//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "JpyLiborSwapIsdaFixAm.h"
using namespace Cephei::QL::Indexes::Swap;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Indexes/SwapIndex.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Instruments/VanillaSwap.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Instruments;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (Cephei::QL::Times::IPeriod^ tenor, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
    CPeriod^ _Ctenor;
    CYieldTermStructure^ _Ch;
    try
    {
#ifdef HANDLE
        _phJpyLiborSwapIsdaFixAm = NULL;
#endif
        _Ctenor = safe_cast<CPeriod^> (tenor);
        _Ctenor->Lock();
        QuantLib::Period& _tenor = static_cast<QuantLib::Period&> (_Ctenor->GetReference ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h))
        {
            _Ch = safe_cast<CYieldTermStructure^> (h->Value);
            _Ch->Lock();
        }
        Handle<QuantLib::YieldTermStructure>& _h = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h) ? static_cast<Handle<QuantLib::YieldTermStructure>&> (_Ch->GetHandle ()) : Handle<QuantLib::YieldTermStructure>()); //1
        _ppJpyLiborSwapIsdaFixAm = new boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm> (new QuantLib::JpyLiborSwapIsdaFixAm ( _tenor,  _h ));
        SetSwapIndex (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ctenor != nullptr) _Ctenor->Unlock();
        if (_Ch != nullptr) _Ch->Unlock();
    }
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Termstructures::IYieldTermStructure^ forwarding, Cephei::QL::Termstructures::IYieldTermStructure^ discounting) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
    CPeriod^ _Ctenor;
    CYieldTermStructure^ _Cforwarding;
    CYieldTermStructure^ _Cdiscounting;
    try
    {
#ifdef HANDLE
        _phJpyLiborSwapIsdaFixAm = NULL;
#endif
        _Ctenor = safe_cast<CPeriod^> (tenor);
        _Ctenor->Lock();
        QuantLib::Period& _tenor = static_cast<QuantLib::Period&> (_Ctenor->GetReference ()); 
        _Cforwarding = safe_cast<CYieldTermStructure^> (forwarding);
        _Cforwarding->Lock();
        Handle<QuantLib::YieldTermStructure>& _forwarding = static_cast<Handle<QuantLib::YieldTermStructure>&> (_Cforwarding->GetHandle ()); 
        _Cdiscounting = safe_cast<CYieldTermStructure^> (discounting);
        _Cdiscounting->Lock();
        Handle<QuantLib::YieldTermStructure>& _discounting = static_cast<Handle<QuantLib::YieldTermStructure>&> (_Cdiscounting->GetHandle ()); 
        _ppJpyLiborSwapIsdaFixAm = new boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm> (new QuantLib::JpyLiborSwapIsdaFixAm ( _tenor,  _forwarding,  _discounting ));
        SetSwapIndex (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ctenor != nullptr) _Ctenor->Unlock();
        if (_Cforwarding != nullptr) _Cforwarding->Unlock();
        if (_Cdiscounting != nullptr) _Cdiscounting->Unlock();
    }
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm>& childNative, Object^ owner) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
#ifdef HANDLE
	_phJpyLiborSwapIsdaFixAm = NULL;
#endif
	_ppJpyLiborSwapIsdaFixAm = &childNative;
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (QuantLib::JpyLiborSwapIsdaFixAm& childNative, Object^ owner) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
#ifdef HANDLE
	_phJpyLiborSwapIsdaFixAm = NULL;
#endif
	_ppJpyLiborSwapIsdaFixAm = new boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm> (&childNative);
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
    _JpyLiborSwapIsdaFixAmOwner = owner;
    _SwapIndexOwner = owner;
}

Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (CJpyLiborSwapIsdaFixAm^ copy) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
#ifdef HANDLE
	_phJpyLiborSwapIsdaFixAm = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppJpyLiborSwapIsdaFixAm = new boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm> (copy->GetShared());
        _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
    }
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (PLATFORM::Type^ t) : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
#ifdef HANDLE
	_phJpyLiborSwapIsdaFixAm = NULL;
#endif
	if (!t->IsSubclassOf(CJpyLiborSwapIsdaFixAm::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (QuantLib::Handle<QuantLib::JpyLiborSwapIsdaFixAm>& childNative, Object^ owner)  : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
	_phJpyLiborSwapIsdaFixAm = &childNative;
	_ppJpyLiborSwapIsdaFixAm = &static_cast<boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm>>(childNative.currentLink());
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
    _JpyLiborSwapIsdaFixAmOwner = owner;
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (QuantLib::Handle<QuantLib::JpyLiborSwapIsdaFixAm> childNative)  : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
	_phJpyLiborSwapIsdaFixAm = &childNative;
	_ppJpyLiborSwapIsdaFixAm = &static_cast<boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm>>(childNative.currentLink());
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::CJpyLiborSwapIsdaFixAm (QuantLib::JpyLiborSwapIsdaFixAm childNative)  : CSwapIndex(CJpyLiborSwapIsdaFixAm::typeid)
{
#ifdef HANDLE
	_phJpyLiborSwapIsdaFixAm = NULL;
#endif
	_ppJpyLiborSwapIsdaFixAm = new boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm> (new QuantLib::JpyLiborSwapIsdaFixAm (childNative));
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppJpyLiborSwapIsdaFixAm));
}
#endif

Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::~CJpyLiborSwapIsdaFixAm ()
{
    if (_ppJpyLiborSwapIsdaFixAm != NULL)
    {
	    delete _ppJpyLiborSwapIsdaFixAm;
        _ppJpyLiborSwapIsdaFixAm = NULL;
    }
}
Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::!CJpyLiborSwapIsdaFixAm ()
{
    if (_ppJpyLiborSwapIsdaFixAm != NULL)
    {
	    delete _ppJpyLiborSwapIsdaFixAm;
    }
}
QuantLib::JpyLiborSwapIsdaFixAm& Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::GetReference ()
{
    if (_ppJpyLiborSwapIsdaFixAm == NULL) throw REFNEW NativeNullException ();
	return **_ppJpyLiborSwapIsdaFixAm;
}
boost::shared_ptr<QuantLib::JpyLiborSwapIsdaFixAm>& Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::GetShared ()
{
    if (_ppJpyLiborSwapIsdaFixAm == NULL) throw REFNEW NativeNullException ();
	return *_ppJpyLiborSwapIsdaFixAm;
}
QuantLib::JpyLiborSwapIsdaFixAm* Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::GetPointer ()
{
    if (_ppJpyLiborSwapIsdaFixAm == NULL) throw REFNEW NativeNullException ();
	return &**_ppJpyLiborSwapIsdaFixAm;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::JpyLiborSwapIsdaFixAm>& Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::GetHandle ()
{
	if (_phJpyLiborSwapIsdaFixAm == NULL)
	{
		_phJpyLiborSwapIsdaFixAm = new Handle<QuantLib::JpyLiborSwapIsdaFixAm> (*_ppJpyLiborSwapIsdaFixAm);
	}
	return *_phJpyLiborSwapIsdaFixAm;
}
#endif
bool Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm::HasNative () 
{
	return (_ppJpyLiborSwapIsdaFixAm != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::Swap::IJpyLiborSwapIsdaFixAm^ Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm_Factory::Create (Cephei::QL::Times::IPeriod^ tenor, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h)
{
    return REFNEW CJpyLiborSwapIsdaFixAm ( tenor,  h);
}
Cephei::QL::Indexes::Swap::IJpyLiborSwapIsdaFixAm^ Cephei::QL::Indexes::Swap::CJpyLiborSwapIsdaFixAm_Factory::Create (Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Termstructures::IYieldTermStructure^ forwarding, Cephei::QL::Termstructures::IYieldTermStructure^ discounting)
{
    return REFNEW CJpyLiborSwapIsdaFixAm ( tenor,  forwarding,  discounting);
}
